package pl.com.qapps.datastore;

import java.util.HashMap;
import java.util.Map;

import com.google.apphosting.api.ApiProxy;
import com.google.apphosting.api.ApiProxy.Environment;

/**
 * 
 * @author Jakub Dykowski
 * 
 */
public class GaeHelper {
	private static Environment LOCAL_ENVIRONMENT = new LocalEnvironment();

	public static void registerEnvironment() {
		if (ApiProxy.getCurrentEnvironment() == null)
			ApiProxy.setEnvironmentForCurrentThread(LOCAL_ENVIRONMENT);
	}

	public static class LocalEnvironment implements Environment {
		@Override
		public boolean isLoggedIn() {
			// make sure it works properly
			return true;
		}

		@Override
		public boolean isAdmin() {
			// TODO make sure always setting as administrator is good choice
			return true;
		}

		@Override
		public String getVersionId() {
			// TODO Auto-generated method stub
			return "1";
		}

		@Override
		public String getRequestNamespace() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public String getEmail() {
			// TODO find the proper value to return since there will never be
			// any user logged in
			return "jakub.dykowski@gmail.com";
		}

		@Override
		public String getAuthDomain() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public Map<String, Object> getAttributes() {
			// TODO Auto-generated method stub
			// System.out.println("getAttrbutes()");
			return new HashMap<String, Object>();
		}

		@Override
		public String getAppId() {
			// TODO define default app name, there won't be more apps
			return "";
		}

		@Override
		public long getRemainingMillis() {
			// TODO implement deadlines or live without
			return Long.MAX_VALUE;
		}
	}
}
